package com.entor.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MyErrorController implements ErrorController{
	
	@RequestMapping("/error")
	public String handlerError(HttpServletRequest req){
		//获取错误代码(400,404,500,401,406)
		Integer statusCode = (Integer)req.getAttribute("javax.servlet.error.status_code");
		if(statusCode==500){
			return "/error/500";
		}else if(statusCode==400){
			return "/error/400";
		}else if(statusCode==404){
			return "/error/404";
		}else if(statusCode==406){
			return "/error/406";
		}
		return null;
		
	}

	@Override
	public String getErrorPath() {
		return "/error";
	}

}
